<?php
	include_once '../classes/khoahoc_bs.php';
	include_once '../classes/hocvien_bs.php';
	include_once '../classes/hopdong_bs.php';
	include_once '../classes/lophoc_bs.php';
	include_once '../classes/giaovien_bs.php';
	include_once '../classes/buoihoc_bs.php';
	include_once '../classes/chuongtrinhhoc_bs.php';
	include_once '../classes/phonghoc_bs.php';
	$KhoaHoc = new khoahoc_bs();
	$KhoaHoc->SetMaTrangThai(1);
	$DKhoaHoc = $KhoaHoc->LayDanhSach();
	
	$HocVien = new hocvien_bs();
	$SoLuongHV = 0; 
	$SoLuongHopDong = 0; 
	
	$SoLop0 = 0; $SoLop1 = 0;
	if(isset($DKhoaHoc[0]))
	{
		$DHocVien = $HocVien->DSHVTheoKhoa($DKhoaHoc[0]['MaKhoaHoc']);
		$SoLuongHV = $DHocVien == null ? 0 : count($DHocVien);
		
		$HopDong = new hopdong_bs();
		$DHopDong = $HopDong->HDTrongKhoa($DKhoaHoc[0]['MaKhoaHoc']);
		$SoLuongHopDong = $DHopDong == null ? 0 : count($DHopDong);
		
		$LopHoc = new lophoc_bs();
		$LopHoc->SetMaKhoaHoc($DKhoaHoc[0]['MaKhoaHoc']);
		$DLopHoc = $LopHoc->LayDanhSach();
		$SoLop = $DLopHoc == null ? 0 : count($DLopHoc);
	}
?>
<div class="Home">
	<h3 id="TableTitle" align="center" style="font-size: 14px; border-bottom:1px solid #b3b3b3">THÔNG TIN KHÓA VÀ LỚP HỌC MỚI NHẤT</h3>
	<div class="ThongTinKhoa">
		<table>
			<tr>
				<th rowspan="2"><?php echo $DKhoaHoc[0]['TenKhoaHoc']; ?></th>
				<td>Mã khóa</td>
				<td><?php echo $DKhoaHoc[0]['MaKhoaHoc']; ?></td>
				<td>Giáo viên</td>
				<td><?php echo $SoLuongHopDong; ?></td>
				<td>Trợ giảng</td>
				<td><?php echo $SoLuongHV; ?></td>
			</tr>
			<tr>
				<td>Ngày khai giảng</td>
				<td><?php echo ConvertDate($DKhoaHoc[0]['NgayKhaiGiang']); ?></td>
				<td>Số học viên</td>
				<td>100</td>
				<td>Số lớp</td>
				<td>100</td>
			</tr>
		</table>
	</div>
	<br />
	<div class="ThongTinLop">
		<?php
			$LopHoc = new lophoc_bs();
			$LopHoc->SetMaKhoaHoc($DKhoaHoc[0]['MaKhoaHoc']);
			$DLopHoc = $LopHoc->LayDanhSach();
			if($DLopHoc != null)
			{
				$i = 0;
				$j = 0;
				while($i < count($DLopHoc))
				{
					if($DLopHoc[$i]['MaLopHoc'] == "0")
					{
						$i++;
						continue;
					}
					else
					{
		?>
					<div class="Lop">
						<table width="100%">
							<tr>
								<th colspan="2"><a href="index.php?act=hocvien_danhsachlop&mlh=<?php echo $DLopHoc[$i]['MaLopHoc']; ?>"><?php echo $DLopHoc[$i]['MaLopHoc']; ?></a></th>
							</tr>
							<?php
								$HopDong = new hopdong_bs();
								$HopDong->SetMaLopHoc($DLopHoc[$i]['MaLopHoc']);
								$HopDong->SetMaVaiTro('VG01');
								$DHopDong = $HopDong->LayDanhSach();
								if($DHopDong != null)
								{
									$GiaoVien = new giaovien_bs();
									$GiaoVien->SetMaGiaoVien($DHopDong[0]['MaGiaoVien']);
									$DGiaoVien = $GiaoVien->LayDanhSach();
									$HoTenGV = $DGiaoVien == null ? "N/A" : $DGiaoVien[0]['HoTen'];
								}
								else
									$HoTenGV = '<i>Chưa phân công</i>';
									
								//------
								
								$HocVien = new hocvien_bs();
								$HocVien->SetMaLopHoc($DLopHoc[$i]['MaLopHoc']);
								$DHocVien = $HocVien->LayDanhSach();
								$HVLop = $DHocVien == null ? 0 : count($DHocVien);
								
								//------
								
								$ChuongTrinhHoc = new chuongtrinhhoc_bs();
								$ChuongTrinhHoc->SetMaChuongTrinh($DLopHoc[$i]['MaChuongTrinh']);
								$DChuongTrinhHoc = $ChuongTrinhHoc->LayDanhSach();
								$SoTiet = $DChuongTrinhHoc == null ? "N/A" : $DChuongTrinhHoc[0]['SoTiet'];
								$CTH = $DChuongTrinhHoc == null ? "N/A" : $DChuongTrinhHoc[0]['TenChuongTrinh'];
								$MCTH = $DChuongTrinhHoc == null ? "N/A" : $DChuongTrinhHoc[0]['MaChuongTrinh'];
								
								//-----
								
								$PhongHoc = new phonghoc_bs();
								$PhongHoc->SetMaPhong($DLopHoc[$i]['MaPhong']);
								$DPhongHoc = $PhongHoc->LayDanhSach();
								$PhongLopHoc = $DPhongHoc == null ? "N/A" : $DPhongHoc[0]['MaPhong'];
								
								//-----
								
								$BuoiHoc = new buoihoc_bs();
								$BuoiHoc->SetMaLopHoc($DLopHoc[$i]['MaLopHoc']);
								$DBuoiHoc = $BuoiHoc->LayDanhSach();
								$SoTietDaHoc = 0;
								if($DBuoiHoc != null)
								{
									for($i = 0; $i < count($DBuoiHoc); $i++)
									{
										$SoTietDaHoc += $DBuoiHoc[$i]['SoTietHoc'];	
									}
								}
							?>
							
							<tr>
								<td>Giáo viên</td>
								<td ><?php echo $HoTenGV; ?></td>
							</tr>
							<tr>
								<td>Học viên</td>
								<td ><?php echo $HVLop; ?></td>
							</tr>
							<tr>
								<td>Phòng học</td>
								<td><?php echo $PhongLopHoc; ?></td>
							</tr>
							<tr>
								<td>Số tiết</td>
								<td ><?php echo $SoTiet; ?></td>
							</tr>
							<tr>
								<td>Chương trình</td>
								<td title="<?php echo $CTH; ?>"><?php echo $MCTH; ?></td>
							</tr>
							<tr>
								<td>Đã học</td>
								<td ><?php echo round($SoTietDaHoc); ?></td>
							</tr>
						</table>
					</div>
		<?php
					$i++;
					}
				}
			}
		?>
	</div>
	
</div>